package ScoreBL;

import java.rmi.RemoteException;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import vo.ScoreCellVO;
import vo.ScoreVO;

public class ScoreTest
{
	ScoreController sc;
	ScoreVO sv;
	ScoreCellVO scv;
	
	@Before
	public void init() throws RemoteException
	{
		sc = new ScoreController();
		
		scv=new ScoreCellVO();
		scv.score="0";
		scv.studentID="test001";
		scv.lessonID="test001";
		
		sv = new ScoreVO();
		sv.list.add(scv);
		
	}
	@Test
	public void testInsertCell() throws RemoteException
	{
		assertTrue(!sc.insertCell(scv));
	}

	@Test
	public void testGetOfStudent() throws RemoteException
	{
		ScoreVO receive = sc.getOfStudent("test001");
		assertTrue(receive.list.size()==1);
		assertTrue(receive.list.get(0).score.equals("0"));
		receive = sc.getOfStudent("wrongnumber");
		assertTrue(receive.list.size()==0);
	}

	@Test
	public void testSet() throws RemoteException
	{
		scv.score="1";
		sc.set(sv);
		assertTrue(sc.getOfStudent("test001").list.get(0).score.equals("1"));

		scv.score="0";
		sc.set(sv);
		assertTrue(sc.getOfStudent("test001").list.get(0).score.equals("0"));
	}

	@Test
	public void testGetOfTeacher() throws RemoteException
	{
		ScoreVO receive = sc.getOfTeacher("test001");
		assertTrue(receive.list.size()==1);
		assertTrue(receive.list.get(0).score.equals("0"));
		
		receive = sc.getOfTeacher("wrongnumber");
		assertTrue(receive.list.size()==0);
	}

	@Test
	public void testDelCell() throws RemoteException
	{
		assertTrue(sc.delCell(scv));
		assertTrue(sc.getOfStudent("test001").list.size()==0);
		assertTrue(sc.insertCell(scv));
		assertTrue(sc.getOfStudent("test001").list.size()==1);
	}
}
